package demo17_SinglePattern;

import java.lang.reflect.Constructor;

/**
 * @author kunkun
 * @className Test07_Lazy
 * @Description 枚举类型实现单例模式
 * @date 2025/3/8 18:15
 */
public enum Test07_Lazy {

    date;

    public static Test07_Lazy getInstance(){
        return date;
    }

    public static void main(String[] args) throws Exception {
        Test07_Lazy instance1 = Test07_Lazy.getInstance();
        Test07_Lazy instance2 = Test07_Lazy.getInstance();
        System.out.println(instance1==instance2);   //true

        //天然防止反射
        Class<Test07_Lazy> aClass = Test07_Lazy.class;
        Constructor<Test07_Lazy> constructor = aClass.getDeclaredConstructor(String.class, int.class);
        constructor.setAccessible(true);
        Test07_Lazy test07Lazy = constructor.newInstance();
    }

}
